/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package util;


import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.misc.BASE64Encoder;

/**
 *
 * @author Neo
 */
public class Md5Generator {

    public static String getMd5(String plaintext) {
        try {
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.reset();
            m.update(plaintext.getBytes());
            byte[] digest = m.digest();
            BigInteger bigInt = new BigInteger(1, digest);
            String hashtext = bigInt.toString(16);
            // Now we need to zero pad it if you actually want the full 32 chars.
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            BASE64Encoder bs = new BASE64Encoder();
            String rText = bs.encode(hashtext.getBytes());
            return rText;
        } catch (NoSuchAlgorithmException ex) {
            Logger.getLogger(Md5Generator.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;


    }
}
